package com.byxy.provider;

import org.apache.ibatis.jdbc.SQL;

import com.byxy.entity.User;

public class UserProvider {
	public String insert(User u) {
//		@Insert("insert into user(user_name,user_nick,user_password,user_type) values(#{userName},#{userNick},#{userPassword},#{userType})")
		return new SQL() {
			{
				INSERT_INTO("user");
				if(u.getUserName() != null) {
					VALUES("user_name","#{userName}");
				};
				if(u.getUserNick() != null) {
					VALUES("user_nick","#{userNick}");
				};
				if(u.getUserPassword() != null) {
					VALUES("user_password","#{userPassword}");
				};
				if(u.getUserType() != null) {
					VALUES("user_type","#{userType}");
				};
			}
		}.toString();
	}
	
	public String update(User u) {
		return new SQL() {
			{
				INSERT_INTO("user");
				if(u.getUserName() != null) {
					SET("user_name","#{userName}");
				};
				if(u.getUserNick() != null) {
					SET("user_nick","#{userNick}");
				};
				if(u.getUserPassword() != null) {
					SET("user_password","#{userPassword}");
				};
				if(u.getUserType() != null) {
					SET("user_type","#{userType}");
				};
				WHERE("user_id=#{userId}");
			}
		}.toString();
	}
}
